//
//  SEOnlineReserveIntroduceButtonView.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/7.
//

import UIKit

@IBDesignable class SEOnlineReserveIntroduceButtonView: UIView {
    
    var viewIntroductionClosure: (() -> Void)?
    var confirmReservationClosure: (() -> Void)?
    
    var view: UIView!

    @IBAction private func viewGraphicConsultationIntroduction() {
        viewIntroductionClosure?()
    }
    
    @IBAction private func confirmReservation() {
        confirmReservationClosure?()
    }
    
    @IBOutlet private weak var confirmButton: UIButton! {
        didSet {
            confirmButton.isIgnoreEvent = false
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupUI()
    }
    
    private func setupUI() {
        view = loadViewFromNib()
        view.backgroundColor = .background
        
        confirmButton.setLayerCorners(rect: confirmButton.bounds,
                                      radius: confirmButton.bounds.height / 2)
    }
    
    private func loadViewFromNib() -> UIView {
        let bundle = Bundle(for: type(of: self))
        let nib = UINib(nibName: nibName(), bundle: bundle)
        let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView

        view.frame = bounds
        view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        addSubview(view)

        return view
    }

    private func nibName() -> String {
        return String(describing: type(of: self))
    }
}
